package mate.task.odin;

import java.io.Serializable;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Represents a date
 * @author Leonard
 * @version 1.0
 */
public class Date implements Comparable, Serializable{

	private static final long serialVersionUID = 1L;
	private int month, day, year;

	/**
	 * Creates a new day with given month/day/year
	 * @param month The month
	 * @param day The day
	 * @param year The year
	 */
	public Date(int month, int day, int year){
		this.month = month;
		this.day = day;
		this.year = year;
	}

	/**
	 * Returns the month
	 * @return The month
	 */
	public int getMonth(){
		return month;
	}
	
	public String dayOfWeek(){
		Calendar cal = new GregorianCalendar(year, month, day);
		int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
		
		String s = "";
		
		switch(dayOfWeek){
		case 0:
			s = "MONDAY";
			break;
		case 1:
			s = "TUESDAY";
			break;
		case 2:
			s = "WEDNESDAY";
			break;
		case 3:
			s = "THURSDAY";
			break;
		case 4:
			s = "FRIDAY";
			break;
		case 5:
			s = "SATURDAY";
			break;
		case 6:
			s = "SUNDAY";
			break;
		}
		
		return s;
	}

	/**
	 * Returns the day
	 * @return The day
	 */
	public int getDay(){
		return day;
	}

	/**
	 * Returns the year
	 * @return The year
	 */
	public int getYear(){
		return year;
	}

	/**
	 * Returns a String representation of this date
	 * @return A String representation of this date
	 */
	public String toString(){
		return (month + "/" + day + "/" + year);
	}

	/**
	 * Returns whether or not this date is before/after another
	 * @param o The date to compare to
	 * @returns Positive if this date is after Date o, negative if this date
	 * 			is before Date o, 0 if they are equal
	 */
	public int compareTo(Object o){
		if(!(o instanceof Date))
			return 1;

		Date other = (Date)o;

		if(year != other.getYear()){
			return (year - other.getYear());
		}else if(month != other.getMonth()){
			return (month - other.getMonth());
		}else{
			return (day - other.getDay());
		}
	}
}
